//
//  EFengOrgnizationSelectionCell.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/1/21.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengOrgnizationSelectionCell.h"

@implementation EFengOrgnizationSelectionCell

+ (instancetype)eFengOrgnizationSelectionCellWithTableView:(UITableView *)tableView
{
    static NSString *OrgnizationSelectionCellId = @"OrgnizationSelectionCellId";
    EFengOrgnizationSelectionCell *cell = [tableView dequeueReusableCellWithIdentifier:OrgnizationSelectionCellId];
    if (cell == nil) {
        cell = [[EFengOrgnizationSelectionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:OrgnizationSelectionCellId];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupOrgSub];
    }
    return self;
}


- (void)setupOrgSub
{
//    WeakProperty UIView *seperatorLine;
//    WeakProperty UILabel *departNameLabel;
//    WeakProperty UIImageView *rightArrow;
//    WeakProperty UILabel *departCountLabel;
//    WeakProperty UIButton *departIcon;
//    WeakProperty UIButton *selectIcon;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"ico-circleDefault"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"ico-circleClick"] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:btn];
    self.selectIcon = btn;
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"icon-Group"] forState:UIControlStateNormal];
    [btn1 setImage:[UIImage imageNamed:@"icon-Group"] forState:UIControlStateSelected];
    btn1.userInteractionEnabled = NO;
    [self.contentView addSubview:btn1];
    self.departIcon = btn1;
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"rightArrow"];
    [self.contentView addSubview:imageView];
    self.rightArrow = imageView;
    
    UIView *sepratiorline = [[UIView alloc] init];
    sepratiorline.backgroundColor = RGBCOLOR(212, 212, 212);
    [self.contentView addSubview:sepratiorline];
    self.seperatorLine = sepratiorline;
    
    UILabel *label1 = [[UILabel alloc] init];
    label1.textAlignment = UITextAlignmentLeft;
    label1.textColor = BlackColor;
    [self.contentView addSubview:label1];
    self.departNameLabel = label1;
    
    UILabel *label2 = [[UILabel alloc] init];
    label2.textAlignment = UITextAlignmentRight;
    label2.textColor = BlackColor;
    [self.contentView addSubview:label2];
    self.departCountLabel = label2;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.selectIcon.frame = CGRectMake(0.0f, 0, self.selectIcon.currentImage.size.width + 30.0f, self.height);
    self.departIcon.frame = CGRectMake(CGRectGetMaxX(self.selectIcon.frame), 0, self.departIcon.currentImage.size.width, self.height);
    self.rightArrow.frame = CGRectMake(self.width - self.rightArrow.image.size.width, 0, self.rightArrow.image.size.width, self.height);
    self.departCountLabel.frame = CGRectMake(self.rightArrow.x - 50.0f + 40.0f, 0, 50.0f, self.height);
    self.departNameLabel.frame = CGRectMake(CGRectGetMaxX(self.departIcon.frame) + 5.0f, 0, self.departCountLabel.x - CGRectGetMaxX(self.departIcon.frame) - 5.0f, self.height);
    self.seperatorLine.frame = CGRectMake(0, self.height - 0.5f, self.width, 0.5f);
}
- (void)btnClick
{
    if ([self.orgnizationDelegate respondsToSelector:@selector(EFengOrgnizationSelectionCellDidSelectWithIndexPath:tableView:)]) {
        [self.orgnizationDelegate EFengOrgnizationSelectionCellDidSelectWithIndexPath:self.cellIndexPath tableView:self.tableView];
    }
}
@end
